package com.example.project.service.impl;

import com.example.project.dao.IUserDao;
import com.example.project.entity.User;
import com.example.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *作者：金照富
 * 2023年11月3日
 */
@Service
public class IUserServiceImpl implements IUserService {

    @Autowired
    private IUserDao user1Mapper;
    @Override
    public int insertUser1(User user1) {
        int user1Value;
        User user11=new User();
        user11.setUserName(user1.getUserName());
        List<User> allUser1=user1Mapper.getAllUser1(user11);
        if(allUser1.size()>=1){
            user1Value = -1;
        }else {
            user1Value= user1Mapper.insertUser1(user1);
        }
        return user1Value;
    }

    @Override
    public int deleteUser1(User user1) {
        int user1Value;
        User user11=new User();
        user11.setUserName(user1.getUserName());
        List<User> allUser1=user1Mapper.getAllUser1(user11);
        if(allUser1.size()==0){
            user1Value = -1;
        }else {
            user1Value= user1Mapper.deleteUser1(user1);
        }
        return user1Value;
    }

    @Override
    public int updateUser1(User user1) {
        int user1Value;
        User user11=new User();
        user11.setUserName(user1.getUserName());
        List<User> allUser1=user1Mapper.getAllUser1(user11);
        if(allUser1.size()>=1){
            user1Value = -1;
        }else {
            user1Value= user1Mapper.updateUser1(user1);
        }
        return user1Value;
    }

    @Override
    public List<User> getAllUser1(User user1) {
        return user1Mapper.getAllUser1(user1);
    }

    @Override
    public User getUser1(User user1) {
        return user1Mapper.getUser1(user1);
    }
}
